<?php session_start();
if (!isset($_SESSION["level"])) header("location:login.php");
// else if ( $_SESSION["level"] != "admin" ) header("location:index.php");
?>
<!DOCTYPE html>
<html>
 <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <link rel="shortcut icon" href="./files/img/favicon.ico">
  <title>RemindMe</title>

  <link type="text/css" href="./files/jquery-ui/css/smoothness/jquery-ui-1.8.16.custom.css" rel="Stylesheet" />	
  <script type="text/javascript" src="./files/jquery-1.6.4.js"></script>
  <script type="text/javascript" src="./files/jquery-ui/js/jquery-ui-1.8.16.custom.min.js"></script>

  <style type="text/css">
    @import "style2.css";
  </style>

  <script type="text/javascript" src="./scripts.js"></script>
</head>
 <?php 
   include 'sql.php';
 ?>

<body>

<div id="access">
  <?php showRightPanel(); ?>
</div> <!--End of access-->

  <!--
  Start Header Area
  -->
<div id="header">
</div><!-- End of HEADER -->

<div id="ribbon">
  <table>
    <tr>

    </tr>
  </table>
</div><!--End of ribbon-->

 <!--
  Start Left Panel Area
  -->
 <?php showLeftPanel($_SESSION['level'], $_SESSION['user']); ?>
    <!--
    End of Left_panel
    -->

 <!--
  Start Container Area
  -->
 <div id="container">
  <div id="content"><!-- Content Area-->
    <form id="users" action="sql.php" method="post">
      <label>Select User:</label><br>
      <select name="username">
	<?php // Dynamically populates the drop list
	    $level = $_SESSION['level'];
	    $user = $_SESSION['user'];
	    if ($level == "admin") {
 	      $query = mysql_query("SELECT username FROM USERS;");
	    }
	    else {
 	      $query = mysql_query("SELECT username FROM USERS WHERE username='$user';");
	    }
	    while($rows = mysql_fetch_array($query)) {
	      echo "<option value=\"$rows[0]\">$rows[0]</option>\n";
	    }//end of while 
	?>
      </select><br>
      <label>Type current password:</label><br>
      <input type="password" id="current_password" name="current_password"/><br>
      <label>Type new password:</label><br>
      <input type="password" id="new_password" name="new_password"/><p></p><br>
      <label>Confirm:</label><img id="img"><br>
      <input type="password" id="password_confirm"><br><br>
      <input type="submit" value="Change!" id="submit" name="submit_change_pass" disabled><br>
    </form>
  </div><!--END of content-->
</div><!--END of container-->

<?php showFooter(); ?><!--END of footer-->

<script>
$(document).ready(function(){
//   $("#new_password").focusout(function() {
//     var current_password = $("#current_password").val();
//     var new_password = $("#new_password").val();
//     var password_confirm = $("#password_confirm").val();
//     if (current_password == new_password) {
//        $("p").text("The new password is the same as the current");
//     }
//     else {
//       $("#password_confirm").removeAttr('disabled');
//     }
//   });
  $("#password_confirm").focusout(function(){
    var current_password = $("#current_password").val();
    var password = $("#new_password").val();
    var password_confirm = $("#password_confirm").val();
    if (password != "") {
      if (password == password_confirm) {
	$("#img").attr('src', './files/img/tick.jpg');
	$("#submit").removeAttr('disabled');

      }
      else {
	$("#img").attr('src', './files/img/wrong.png');
      }
    }// end of outer if
    else {
      $("#img").attr('src', '');
    }
  });
/*  
  $("#submit").click(function() {
    var new_password = $("#new_password").val();
    var dataString = 'new_password=' + new_password;

    $.ajax({
      type: "POST",
      url: "sql.php",
      data: dataString,
      cache: false,
      success: function(html) {}
    });
  });*/
});//end of ready
</script>
</body>
</html>